package com.his.struts.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import com.his.struts.form.UserForm;
/**
 * 
 * @author student
 *
 */
public class BackstageFilter implements Filter {
	
	Logger log = Logger.getLogger(BackstageFilter.class);
	public void destroy() {
		log.info("后台---过滤器已关闭");
	}
	
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpServletResponse rep = (HttpServletResponse) response;
		HttpServletRequest req = (HttpServletRequest) request;
		HttpSession session = req.getSession();
		UserForm userForm = (UserForm) session.getAttribute("adminLogined");
		if (null == userForm) {
			rep.sendRedirect("/his/gblogin.jsp");
		} else {
			chain.doFilter(request, response);
		}
	}

	public void init(FilterConfig arg0) throws ServletException {
		log.info("后台---过滤器已启动");
	}

}
